package com.jyy.prefabricated.controller;


import com.jyy.prefabricated.common.AjaxResult;
import com.jyy.prefabricated.entity.ExamPaperArea;
import com.jyy.prefabricated.service.ExamPaperAreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 考试试卷区域
 * @version 1.0.0
 * @author: zjj
 */
@Slf4j
@RequestMapping("/api")
@RestController
public class ExamPaperAreaController {

    @Autowired
    private ExamPaperAreaService areaService;

    /**
     * 新增考试试卷区域
     * @param area
     * @return
     */
    @PostMapping("/exam-paper-area")
    public AjaxResult insert(@Valid @RequestBody ExamPaperArea area){
        log.info("Rest request to insert exam-paper-area:{}",area);
        int id = areaService.insert(area);
        ExamPaperArea result = areaService.selectById(id);
        return AjaxResult.success(result);
    }

    /**
     * 修改考试试卷区域
     * @param area
     * @return
     */
    @PutMapping("/exam-paper-area")
    public AjaxResult update(@Valid @RequestBody ExamPaperArea area){
        log.info("Rest request to update exam-paper-area:{}",area);
        areaService.update(area);
        ExamPaperArea result = areaService.selectById(area.getId());
        return AjaxResult.success(result);
    }

    /**
     * 查询考试试卷区域详情
     * @param id
     * @return
     */
    @GetMapping("/exam-paper-area/{id}")
    public AjaxResult selectById(@PathVariable Integer id){
        log.info("Rest request to find exam-paper-area by id:{}",id);
        ExamPaperArea result = areaService.selectById(id);
        return AjaxResult.success(result);
    }

    /**
     * 删除考试试卷区域
     * @param id
     * @return
     */
    @DeleteMapping("/exam-paper-area/{id}")
    public AjaxResult deleteById(@PathVariable Integer id){
        log.info("Rest request to delete exam-paper-area by id:{}",id);
        int row = areaService.delete(id);
        if(row > 0){
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }


}
